<template>
    <h2>房号修改页面</h2>
    <table border="1">
        <tr>
            <td>房号名称</td>
            <td>
                <input type="text" v-model="num.RN_Name" />
            </td>
        </tr>
        <tr>
            <td>房号楼层</td>
            <td>
                <input type="text" v-model="num.RN_Floor" />
            </td>
        </tr>
        <tr>
            <td>具体房间号</td>
            <td>
                <input type="text" v-model="num.RN_Num" />
            </td>
        </tr>
        <tr>
            <td>房号状态</td>
            <td>
                <input type="radio" :value="true" v-model="num.RN_State" />启用
                <input type="radio" :value="false" v-model="num.RN_State" />禁用
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="修改" @click="editNum"  />
            </td>
        </tr>
    </table>
</template>


<script setup lang="ts">
import {ref,onMounted} from 'vue'
import {useRouter} from 'vue-router'
const router=useRouter();
import axios from 'axios'
const params=new URLSearchParams(location.search);
const RN_Id=params.get('RN_Id');
const num=ref( {
    "RN_Id": 1,
      "RN_Name": "",
      "RN_Floor": null,
      "RN_Num": null,
      "RN_State": true
    })
    const editNum=()=>{
        axios.put('https://localhost:44320/api/Room/NumberEdit',{  
            "RN_Id": RN_Id,      
      "RN_Name": num.value.RN_Name,
      "RN_Floor":num.value.RN_Floor,
      "RN_Num": num.value.RN_Num,
      "RN_State": num.value.RN_State
        })
        .then(res=>{
            if(res.data>0)
            {
                alert('修改成功');
                router.push('/showNumber');
            }
            else
            {
                alert('修改失败');
            }
        })
    }
    onMounted(()=>{
        axios.get('https://localhost:44320/api/Room/NumberBack',{
            params:{
                RN_Id:RN_Id
            }
        })
        .then(res=>{
            num.value=res.data;
        })
    })
</script>